package org.example;

import com.mysql.jdbc.Driver;

import java.sql.*;

public class JdbcConnectCode1 {
    public static void main(String[] args) throws SQLException {
        //创建Driver对象
        Driver driver = new Driver();
        //注册驱动
        DriverManager.registerDriver(driver);
        String url = "jdbc:mysql://121.41.77.32:3306/school_demo?useSSL=false";
        String user= "root";
        String password="123456";
        Connection con = DriverManager.getConnection(url,user,password);


        String sql1 ="select * from school_info";
        //获取操作对象
        Statement statement = con.createStatement();

        //执行sql语句
        ResultSet resultSet = statement.executeQuery(sql1);

        while (resultSet.next()){
            String school_name =resultSet.getString("school_name");
            String school_city = resultSet.getString("school_city");
            System.out.println(String.format("%s \t %s",school_name,school_city));
        }

        con.close();
        statement.close();

    }
}
